﻿using System;
using System.Windows;
using HandyControl.Controls;
using HandyControl.Data;
using OpenFileTransfer.Wpf.Events;
using Prism.Events;
using Prism.Mvvm;

namespace OpenFileTransfer.Wpf.ViewModels
{
    internal class MainWindowViewModel : BindableBase
    {
        public static string GrowToken => @"AppGrowToken";

        public MainWindowViewModel(IEventAggregator eventAggregator)
        {
            eventAggregator.GetEvent<ShowGrowlWarningEvent>().Subscribe(OnShowGrowlWarning);
            eventAggregator.GetEvent<ShowGrowlSuccessEvent>().Subscribe(OnShowGrowlSuccess);
        }

        private void OnShowGrowlWarning(string message)
        {
            Application.Current?.Dispatcher.BeginInvoke(new Action(() => { ShowWarning(message); }), null);
        }

        private void OnShowGrowlSuccess(string message)
        {
            Application.Current?.Dispatcher.BeginInvoke(new Action(() => { ShowSuccess(message); }), null);
        }

        #region 通知信息

        private void ShowWarning(string message)
        {
            Growl.Warning(new GrowlInfo()
            {
                Message = message,
                ShowDateTime = false,
                Token = GrowToken,
                WaitTime = 3
            });
        }

        // ReSharper disable once UnusedMember.Local
        private void ShowSuccess(string message)
        {
            Growl.Success(new GrowlInfo()
            {
                Message = message,
                ShowDateTime = false,
                Token = GrowToken,
                WaitTime = 3
            });
        }

        #endregion
    }
}
